// pages/childFollowUp/childFollowUpDetail/childFollowUpDetail.js
const app = getApp();
var util = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ptTaskInfoSearchVo: null,
    defaultDate: util.formatDate(new Date((new Date().getTime() + 24 * 3600 * 1000))),
    startTime: null,
    endTime: null,
    intervalTime: null,
    executeTime: null,
    noMessage: false,
    navbarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '随访提醒详情', //导航栏 中间的标题
    },
    navHeight: app.globalData.statusBarHeight * 2 + 86,
    defaultTime: "08:30",

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    setTimeout(function(){
      wx.request({
        url: app.getUrl('/xcx/pt/followUpDetail'),
        method: 'GET',
        header: wx.getStorageSync('cookie'),
        data: {
          messageId: options.id
        },
        success(res) {
          if (res.data.code == 0) {
            that.setData({
              messageId: options.id,
              ptTaskInfoSearchVo: res.data.data,
              //获取后台的windowDay和executeTime
              intervalTime: res.data.data.windowDay,
              executeTime: res.data.data.executeTime,
            })
            
          } else if (res.data.code == 404) {
            that.setData({
              noMessage: true
            })
          }
          wx.hideLoading();
        }
      })
    },2000)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  bindDateChange: function (e) {
    this.setData({
      defaultDate: e.detail.value
    })
  },
  bindTimeChange: function (e) {
    this.setData({
      defaultTime: e.detail.value
    })
  },
  // 发起线上随访
  saveUpdateDate: function () {
    var that = this
     wx.request({
        url: app.getUrl('xcx/pt/onlineMessage'),
        header: wx.getStorageSync('cookie'),
        data: {
          messageId: that.data.messageId,
          status: 4
        },
        success(res) {
          if (res.data.code == 0) {
            wx.navigateTo({
                url: `/pages/commonWeb/commonWeb?type=online&ptTaskId=${that.data.ptTaskInfoSearchVo.id}&followQueueId=${that.data.ptTaskInfoSearchVo.queueId}`
            })
          }
        }
      })
   
  },
// 已做过随访
  done:function(){
    var that = this
    wx.request({
      url: app.getUrl('xcx/pt/onlineMessage '),
      header: wx.getStorageSync('cookie'),
      data: {
        messageId: that.data.messageId,
        status: 4
      },
      success(res) {
        if (res.data.code == 0) {
          wx.switchTab({
            url: '../../message/message',
          })
        }
      }
    })
  }
  
})